import React from 'react';
import { Row, Col, Form, InputNumber, Input, Button, Table, Select, message } from 'antd';
const R = require('ramda');
import BizParams from '../../../components/commons/BizParams';
import ChooseProduct from '../components/ChooseProduct';
import validator from '../../../utils/Validator'
import Constants from '../../../utils/Constants'
const pricePercent = 0.1;

const FormItem = Form.Item;
export default Form.create({ wrappedComponentRef: true })(class ProductInfo extends React.Component {
    constructor(props) {
        super(props);
        this.initData(props.dataSource, true);
    }

    componentWillReceiveProps(nextProps) {
        if (!R.equals(this.props.dataSource)(nextProps.dataSource)) {
            this.initData(nextProps.dataSource)
        }
    }

    initData = (dataSource, flag) => {
        dataSource = R.isNil(dataSource) ? {} : dataSource;
        let defaultProductList = R.isNil(dataSource.orderProductDetails) ? [] : dataSource.orderProductDetails;
        let defaultPacktypeelse = dataSource.kindpackage && dataSource.kindpackage.split('|').includes('99');
        let defaultRetrodictRate = dataSource.drawertype === "2";
        if (flag) {
            this.state = {
                retrodictFlag: false,   //倒推增加一个刷新价格按钮，避免过多事件的监听，点下一步之前必须保证为false
                packtypeelse: defaultPacktypeelse,
                defaultPacktypeelse: defaultPacktypeelse,
                productList: defaultProductList,
                defaultProductList: defaultProductList,
                defaultRetrodictRate: defaultRetrodictRate,
                retrodictRate: defaultRetrodictRate //true：倒推 false: 正推
            }
        } else {
            this.setState({
                retrodictFlag: false,   //倒推增加一个刷新价格按钮，避免过多事件的监听，点下一步之前必须保证为false
                packtypeelse: defaultPacktypeelse,
                defaultPacktypeelse: defaultPacktypeelse,
                productList: defaultProductList,
                defaultProductList: defaultProductList,
                defaultRetrodictRate: defaultRetrodictRate,
                retrodictRate: defaultRetrodictRate
            })
        }
    }

    form = {};

    drawerMap = {};

    handleCollectForm = () => {
        return this.form;
    }

    handleResetFields = () => {
        this.setState({ packtypeelse: this.state.defaultPacktypeelse, productList: this.state.defaultProductList, retrodictRate: this.state.defaultRetrodictRate, retrodictFlag: false });
        this.props.form.resetFields();
    }

    handleChangeKindPackage = (value) => {
        if (value && value.includes('99')) {
            this.setState({ packtypeelse: true });
        } else {
            this.setState({ packtypeelse: false, packtypeelse: "" });
        }
    }

    handleChangeDrawerType = (value) => {
        this.setState({ retrodictRate: (value === "2") });
        if (value === "1") {//正推的话要清空掉倒推汇率
            this.props.form.setFieldsValue({ retrodictrate: 0, retrodictfee: 0 });
            //清空产品列表的倒推费用跟开票金额
            let productList = R.clone(this.state.productList);
            R.map((row) => {
                row.retrodictcost = 0;
                row.draweramount = 0;
            }, productList)
            this.setState({ productList: productList, retrodictFlag: false });
        }
    }

    checkProductInfo = () => {
        let flag = true
        let currency = ""
        if (this.props.handleGetCurrencyType) {
            currency = this.props.handleGetCurrencyType();
        }
        let productDrawerIds = [];
        let productSupplyGoodsList = [];
        this.props.form.validateFields((errors, values) => {
            if (errors) {
                if (!this.state.packtypeelse) errors = R.omit(['packtypeelse'])(errors);//实际种类
                if (R.isEmpty(errors)) errors = null;
            }
            if (errors) {
                flag = false;
            }
        })
        if (R.isEmpty(this.state.productList)) {
            message.error("请至少选择一个产品!");
            flag = false;
        }
        let customer = R.isNil(this.props.customer) ? {} : this.props.customer;
        let agencyfee = R.isNil(customer.agencyfee) ? 0 : customer.agencyfee / 100;//费率
        if (this.state.retrodictRate && this.props.form.getFieldValue('retrodictrate') === agencyfee) {
            message.error("倒推汇率不能等于代理费率,请重新输入");
            flag = false;
            return;
        };
        if (this.state.retrodictRate && this.state.retrodictFlag) {
            message.error("数据有变，请先点击刷新价格");
            flag = false;
            return;
        };
        let totalpacknum = 0;
        R.map((row) => {
            if (row.productcurrency !== currency) {
                message.error("所选产品币种必须与报关币种保持一致，请重新选择!");
                flag = false;
                return;
            }
            if (R.isNil(row.productnumber) || R.isNil(row.packagenumber) || R.isNil(row.productweight) || R.isNil(row.grossweight) || R.isNil(row.productprice)
                || (this.state.retrodictRate && (R.isNil(row.retrodictcost) || R.isNil(row.draweramount)))) {
                message.error("产品：(" + row.productname + ") 信息不全，除规格外其他为必填项，请补全!");
                flag = false;
                return;
            }

            if(this.props.customer && this.props.customer.businessType != "2") {
                if(R.isNil(row.drawerid)){
                    message.error("请选择产品：(" + row.productname + ") 的开票人!");
                }
            }

            if (!(validator.DECIMAL4.pattern.test(row.productnumber) && validator.DECIMAL4.pattern.test(row.productweight) && validator.DECIMAL4.pattern.test(row.grossweight))
                || (this.state.retrodictRate && !validator.DECIMAL4.pattern.test(row.draweramount))) {
                if (this.state.retrodictRate) message.error("产品：(" + row.productname + ") 信息有误，数量、净重、毛重、倒推开票金额都必须大于0且最多保留四位小数");
                else message.error("产品：(" + row.productname + ") 信息有误，数量、净重、毛重都必须大于0且最多保留四位小数");
                flag = false;
                return;
            }
            if (row.grossweight < row.productweight) {
                message.error("产品：(" + row.productname + ") 毛重不能小于净重");
                flag = false;
                return;
            }
            //会员客户放开价格浮动限制
            if ((row.productprice > row.productoriginalprice * (1 + pricePercent) || row.productprice < row.productoriginalprice * (1 - pricePercent)) && customer.csttype !== '2') {
                message.error("产品：(" + row.productname + ") 单价上下浮动超过10%");
                flag = false;
                return;
            }
            totalpacknum = totalpacknum + (R.isNil(row.packagenumber) ? 0 : row.packagenumber) //总包装件数
            productDrawerIds.push(row.drawerid + "");
        }, this.state.productList)
        // if (this.props.form.getFieldValue("maxpacknum") < totalpacknum && this.props.form.getFieldValue("kindpackage") != "5" && this.props.form.getFieldValue("kindpackage") != "7") {
        //     message.error("产品的包装件数总和不能超过最大包装件数!");
        //     flag = false;
        // }
        if (flag) {
            this.form = R.merge(this.form, this.props.form.getFieldsValue());
            this.form.orderProductDetails = this.state.productList;
        }
        //判断境内货源地是否一致
        //To-Do
        if(this.props.customer && this.props.customer.businessType != '2'){
            if (flag) {
                R.map((drawer) => {
                    if (R.contains(drawer.id + "", productDrawerIds)) {
                        productSupplyGoodsList.push(drawer.supplygoods);
                    }
                }, R.isNil(this.props.drawerList) ? [] : this.props.drawerList);
                if (!R.contains(this.props.form.getFieldValue("supplygoods"), productSupplyGoodsList)) {
                    message.error("境内货源地不在产品所选开票人列表范围内，请重新选择境内货源地或者产品的开票人");
                    flag = false;
                }
            }
        }
        return flag
    };

    handleChangeProductNumber = (record, value) => {
        let productList = R.clone(this.state.productList);
        let customer = R.isNil(this.props.customer) ? {} : this.props.customer;
        let agencyfee = R.isNil(customer.agencyfee) ? 0 : customer.agencyfee / 100;//费率
        let retrodictRate = R.isNil(this.props.form.getFieldValue('retrodictrate')) ? 0 : this.props.form.getFieldValue('retrodictrate');
        R.map((row) => {
            if (row.id === record.id) {
                row.productnumber = value;
                row.productweight = Math.round(value * row.singleweight * 10000) / 10000;
                if (this.state.retrodictRate && retrodictRate !== agencyfee) { //倒推 数量联动单价
                    let draweramount = R.isNil(row.draweramount) || R.isEmpty(row.draweramount) ? 0 : row.draweramount; //倒推开票金额默认为0
                    let retrodictcost = R.isNil(row.retrodictcost) || R.isEmpty(row.retrodictcost) ? 0 : row.retrodictcost; //倒推费用默认为0
                    let productnumber = R.isNil(row.productnumber) || R.isEmpty(row.productnumber) ? 1 : row.productnumber; //数量默认为1
                    row.productprice = ((draweramount * (1 + row.zzrate / 100 - row.taxrate / 100) / (1 + row.zzrate / 100) + retrodictcost) / (retrodictRate - agencyfee) / productnumber).toFixed(4);
                }
                row.totalprice = Math.round(row.productprice * row.productnumber * 100) / 100;

            }
        }, productList)
        this.setState({ productList: productList });
    }

    handleChangePackageNumber = (record, value) => {
        let productList = R.clone(this.state.productList);
        R.map((row) => {
            if (row.id === record.id) {
                row.packagenumber = value;
            }
        }, productList)
        this.setState({ productList: productList });
    }

    handleChangeProductPrice = (record, value) => {
        let productList = R.clone(this.state.productList);
        R.map((row) => {
            if (row.id === record.id) {
                row.productprice = value;
                row.totalprice = Math.round(value * row.productnumber * 100) / 100;
            }
        }, productList)
        this.setState({ productList: productList });
    }

    handleChangeProductWeight = (record, value) => {
        let productList = R.clone(this.state.productList);
        R.map((row) => {
            if (row.id === record.id) {
                row.productweight = value;
            }
        }, productList)
        this.setState({ productList: productList });
    }

    handleChangeGrossWeight = (record, value) => {
        let productList = R.clone(this.state.productList);
        R.map((row) => {
            if (row.id === record.id) {
                row.grossweight = value;
            }
        }, productList)
        this.setState({ productList: productList });
    }

    handleChangeDrawerAmount = (record, value) => {
        this.state.productList.map(item => { if (item.id === record.id) item.draweramount = value });
        this.setState({ retrodictFlag: true });
    }

    handleChangeDrawer = (record, value) => {
        let productList = R.clone(this.state.productList);
        R.map((row) => {
            if (row.id === record.id) {
                row.drawerid = value;
                row.drawername = this.drawerMap[value];
            }
        }, productList)
        this.setState({ productList: productList });
    }

    handleChangeProductSize = (record, e) => {
        let productList = R.clone(this.state.productList);
        R.map((row) => {
            if (row.id === record.id) {
                row.productsize = e.target.value;
            }
        }, productList)
        this.setState({ productList: productList });
    }

    handleDeleteProduct = (record) => {
        let productList = R.difference(this.state.productList, [record])
        this.setState({ productList: productList, retrodictFlag: true });
    }

    handleOpenAddProduct = () => {
        this.props.dispatch({
            type: 'orderProduct/queryProductList',
            payload: {
                productName: '',
                cstId: this.props.cstId,
                page: Constants.DEFAULTPAGE
            }
        });
        this.formRef.handleOpen();
    }


    handleAddProducts = (tempProductList) => {
        this.setState({ productList: R.concat(this.state.productList, tempProductList), retrodictFlag: true });
    }

    handleRefreshAmt = () => {

        //取倒推汇率
        let retrodictrate = this.props.form.getFieldValue("retrodictrate");
        if (!retrodictrate || retrodictrate < 0) { message.error("倒推汇率不能空，且必须大于0"); return; }
        let agencyfee = this.props.customer && this.props.customer.agencyfee ? this.props.customer.agencyfee / 100 : 0;
        let percentfee = this.props.customer && this.props.customer.percentfee ? this.props.customer.percentfee / 100 : 0; //按退税款的5%，出来就是0.05
        if (retrodictrate === agencyfee) { message.error("汇率不能等于代理费率,请重新输入"); return; }
        //取倒推费用
        let retrodictfee = this.props.form.getFieldValue("retrodictfee");
        let productList = this.state.productList ? R.clone(this.state.productList) : [];
        //先循环一次产品，累加开票金额，按比例均摊倒推费用
        let totalDrawerAmt = 0;
        let checkDrawerAmtFlag = false;
        productList.map(item => {
            if (!item.draweramount || retrodictrate < 0) checkDrawerAmtFlag = true;
            else totalDrawerAmt = totalDrawerAmt + item.draweramount;
        })
        if (checkDrawerAmtFlag) { message.error("请先录入所有产品倒推的开票金额，金额不为小于0"); return; }
        //再一次循环计算产品单价，倒推费用
        productList.map(item => {
            let productnumber = item.productnumber ? item.productnumber : 1; //数量没有输入则先默认为1
            item.retrodictcost = Math.round(item.draweramount * retrodictfee / totalDrawerAmt * 100) / 100; //均摊倒推费用，保留两位小数

            //按1美金收取跟按退税款百分比收取手续费的计算公式有差异
            //按退税款百分比公式=====>报关金额=（（开票金额/（1+征））*（1+征-退+（退*百份比））+杂费）/汇率
            //按1美金公式=====>报关金额={［开票金额/（1+征）］*（1+征-退）+杂费}/（汇率-代理费率）
            if(this.props.customer.feemethod === "2"){//按百分比收取
                item.productprice = ((item.draweramount * (1 + item.zzrate / 100 - item.taxrate / 100 + item.taxrate / 100 * percentfee) / (1 + item.zzrate / 100) + item.retrodictcost) / retrodictrate / productnumber).toFixed(4);//计算单价
            } else {//按1美金收取
                item.productprice = ((item.draweramount * (1 + item.zzrate / 100 - item.taxrate / 100) / (1 + item.zzrate / 100) + item.retrodictcost) / (retrodictrate - agencyfee) / productnumber).toFixed(4);//计算单价
            }
            item.totalprice = Math.round(item.productprice * productnumber * 100) / 100;//计算产品总价
        })
        this.setState({ productList, retrodictFlag: false });
    }

    triggleRefreshAmt = () => {
        this.setState({ retrodictFlag: true });
    }

    handleInitColumns = () => {
        return R.without([null], [
            { title: '品名', dataIndex: 'productname', key: 'productname' },
            { title: '型号', dataIndex: 'productmodel', key: 'productmodel' },
            { title: '品牌类型', dataIndex: 'productbranchname', key: 'productbranchname' },
            { title: '品牌', dataIndex: 'productbranch', key: 'productbranch' },
            { title: '币种', dataIndex: 'productcurrency', key: 'productcurrency' },
            {
                title: '数量', dataIndex: 'productnumber', key: 'productnumber',
                render: (text, record, index) => {
                    return (
                        <InputNumber disabled={this.props.disabled} min={0} max={99999999999999} value={record.productnumber} onChange={this.handleChangeProductNumber.bind(this, record)} />
                    )
                }
            },
            { title: '单位', dataIndex: 'productunit', key: 'productunit' },
            {
                title: '包装件数', dataIndex: 'packagenumber', key: 'packagenumber',
                render: (text, record, index) => {
                    return (
                        <InputNumber disabled={this.props.disabled} min={0} max={99999999999999} value={record.packagenumber} onChange={this.handleChangePackageNumber.bind(this, record)} />
                    )
                }
            },
            {
                title: '单价', dataIndex: 'productprice', key: 'productprice',
                render: (text, record, index) => {
                    return (
                        <InputNumber disabled={this.props.disabled} min={0} max={99999999999999} value={record.productprice} onChange={this.handleChangeProductPrice.bind(this, record)} />
                    )
                }
            },
            this.state.retrodictRate ? {
                title: '倒推开票金额(人民币)', dataIndex: 'draweramount', key: 'draweramount',
                render: (text, record, index) => {
                    return (
                        <InputNumber disabled={this.props.disabled} min={0} max={99999999999999} value={record.draweramount} onChange={this.handleChangeDrawerAmount.bind(this, record)} />
                    )
                }
            } : null,
            { title: '单净重(Kg)', dataIndex: 'singleweight', key: 'singleweight' },
            {
                title: '净重(Kg)', dataIndex: 'productweight', key: 'productweight',
                render: (text, record, index) => {
                    return (
                        <InputNumber disabled={this.props.disabled} min={0} max={99999999999999} value={record.productweight} onChange={this.handleChangeProductWeight.bind(this, record)} />
                    )
                }
            },
            {
                title: '毛重(Kg)', dataIndex: 'grossweight', key: 'grossweight',
                render: (text, record, index) => {
                    return (
                        <InputNumber disabled={this.props.disabled} min={0} max={99999999999999} value={record.grossweight} onChange={this.handleChangeGrossWeight.bind(this, record)} />
                    )
                }
            },
            this.props.customer && this.props.customer.businessType === "2" ? null : {
                title: '关联开票人', dataIndex: 'drawername', key: 'drawername',
                render: (text, record, index) => {
                    return (
                        <Select disabled={this.props.disabled} style={{ width: '100%' }} value={record.drawerid + ""} onChange={this.handleChangeDrawer.bind(this, record)}>
                            {
                                !R.isNil(this.props.drawerList) ? this.props.drawerList.map(item => {
                                    if (!R.contains(item.id)(this.drawerMap)) this.drawerMap[item.id] = item.name;
                                    return (<Select.Option value={item.id + ""} key={item.id + ""}>{item.name}: {item.taxplayercode}</Select.Option>);
                                }) : ''
                            }
                        </Select>
                    )
                }
            },
            { title: '货值', dataIndex: 'totalprice', key: 'totalprice' },
            {
                title: '规格', dataIndex: 'productsize', key: 'productsize',
                render: (text, record, index) => {
                    return (
                        <Input maxLength="1000" style={{ width: 'auto' }} value={R.isNil(record.productsize) ? "" : record.productsize} disabled={record.iseffecthscode === "1" || this.props.disabled} onChange={this.handleChangeProductSize.bind(this, record)} />
                    )
                }
            },
            { title: '申报参数', dataIndex: 'productdeclarelements', key: 'productdeclarelements' },
            { title: '退税率', dataIndex: 'taxrate', key: 'taxrate' },
            { title: '增值税率', dataIndex: 'zzrate', key: 'zzrate' },
            {
                title: '操作', key: 'operation',
                render: (text, record, index) => {
                    return (
                        <div><a href="#" disabled={this.props.disabled} onClick={this.handleDeleteProduct.bind(this, record)}>删除</a></div>
                    );
                }
            }]);
    }

    render() {
        let columns = this.handleInitColumns();
        const { getFieldDecorator } = this.props.form;
        let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource;
        let formItemLayout = {
            labelCol: { xs: { span: 24 }, sm: { span: 6 } },
            wrapperCol: { xs: { span: 24 }, sm: { span: 14 } }
        };
        let currency = "";
        let [totalnum, totalweight, totalgross, totleamount, totalpacknum] = [0, 0, 0, 0, 0];
        R.map((product) => {
            currency = product.productcurrency;
            totalnum = totalnum + (R.isNil(product.productnumber) ? 0 : product.productnumber) //总数量
            totalweight = totalweight + (R.isNil(product.productweight) ? 0 : product.productweight) //总净重
            totalgross = totalgross + (R.isNil(product.grossweight) ? 0 : product.grossweight) //总毛重
            totleamount = totleamount + (R.isNil(product.totalprice) ? 0 : product.totalprice) //总货值
            totalpacknum = totalpacknum + (R.isNil(product.packagenumber) ? 0 : product.packagenumber) //总包装件数
        }, this.state.productList);
        totalnum = Math.round(totalnum * 10000) / 10000;
        totalweight = Math.round(totalweight * 10000) / 10000;
        totalgross = Math.round(totalgross * 10000) / 10000;
        totleamount = Math.round(totleamount * 100) / 100;//两位小数 总价只保留两位小数
        totalpacknum = Math.round(totalpacknum * 10000) / 10000;
        this.form.totalnum = totalnum;
        this.form.totalweight = totalweight;
        this.form.totalgross = totalgross;
        this.form.totleamount = totleamount;
        this.form.totalpacknum = totalpacknum;

        //只有自营的按美金收取代理费支持倒推模式
        let disabledDrawerTypes = [];
        let customer = R.isNil(this.props.customer) ? {} : this.props.customer;
        let declarationstyle = this.props.declarationstyle ? this.props.declarationstyle : undefined;
        if (declarationstyle === "2" || customer.csttype === "2" || customer.businessType === "2") disabledDrawerTypes[0] = "2";
        return (
            <div>
                <Form>
                    <Row>
                        <Col span={12}>
                            <FormItem {...formItemLayout} label="开票方式" hasFeedback>
                                {getFieldDecorator('drawertype', {
                                    rules: [{
                                        required: true, message: '请选择开票方式'
                                    }],
                                    initialValue: dataSource.drawertype
                                })(
                                    <BizParams disabled={this.props.disabled} sprCode='drawertype' disabledKeys={disabledDrawerTypes} onChange={this.handleChangeDrawerType.bind(this)} />
                                    )}
                            </FormItem>
                        </Col>
                        {customer.businessType === "2" ?
                            <Col span={12}>
                                <FormItem {...formItemLayout} label="境内货源地" hasFeedback>
                                    {getFieldDecorator('domesticSupply', {
                                        rules: [{
                                            required: true, message: '请输入境内货源地'
                                        }],
                                        initialValue: dataSource.domesticSupply
                                    })(
                                        <Input disabled={this.props.disabled} maxLength={"100"} />
                                    )}
                                </FormItem>
                            </Col>
                            :
                            <Col span={12}>
                                <FormItem {...formItemLayout} label="境内货源地" hasFeedback>
                                    {getFieldDecorator('supplygoods', {
                                        rules: [{
                                            required: true, message: '请选择境内货源地'
                                        }],
                                        initialValue: dataSource.supplygoods
                                    })(
                                        <Select disabled={this.props.disabled} style={{width: '100%'}} showSearch
                                                placeholder="可通过输入关键字搜索"
                                                filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
                                            {
                                                (R.isNil(this.props.supplyGoodsList) ? [] : this.props.supplyGoodsList).map(item => {
                                                    return (<Select.Option value={item.sprName}
                                                                           key={item.sprName}>{item.sprValue}</Select.Option>);
                                                })
                                            }
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                        }
                    </Row>
                    <Row>
                        <Col span={12} style={{ display: this.state.retrodictRate ? "inline-block" : "none" }}>
                            <FormItem {...formItemLayout} label="倒推汇率" hasFeedback>
                                {getFieldDecorator('retrodictrate', {
                                    rules: this.state.retrodictRate ? [{
                                        required: this.state.retrodictRate, message: '请输入倒推汇率',
                                        pattern: validator.DECIMAL4.pattern, message: validator.DECIMAL4.message,
                                    }] : [],
                                    initialValue: dataSource.retrodictrate
                                })(
                                    <InputNumber disabled={this.props.disabled} min={0} max={99999999999999} style={{ width: '100%' }} onChange={this.triggleRefreshAmt.bind(this)} />
                                    )}
                            </FormItem>
                        </Col>
                        <Col span={12} style={{ display: this.state.retrodictRate ? "inline-block" : "none" }}>
                            <FormItem {...formItemLayout} label="倒推费用" hasFeedback>
                                {getFieldDecorator('retrodictfee', {
                                    initialValue: dataSource.retrodictfee ? dataSource.retrodictfee : 0
                                })(
                                    <InputNumber disabled={this.props.disabled} min={0} max={99999999999999} style={{ width: '100%' }} onChange={this.triggleRefreshAmt.bind(this)} />
                                    )}
                            </FormItem>
                        </Col>
                    </Row>
                    <Row>
                        <Col span={12}>
                            <FormItem {...formItemLayout} label="包装方式" hasFeedback>
                                {getFieldDecorator('packtype', {
                                    rules: [{
                                        required: true, message: '请选择包装方式'
                                    }],
                                    initialValue: dataSource.packtype
                                })(
                                    <BizParams disabled={this.props.disabled} sprCode='packtype' />
                                    )}
                            </FormItem>
                        </Col>
                        <Col span={12}>
                            <FormItem {...formItemLayout} label="最大包装件数" hasFeedback>
                                {getFieldDecorator('maxpacknum', {
                                    rules: [{
                                        required: true, message: '请输入最大包装件数',
                                    }],
                                    initialValue: dataSource.maxpacknum
                                })(
                                    <InputNumber disabled={this.props.disabled} min={1} max={99999999999999} precision={0} style={{ width: '100%' }} />
                                    )}
                            </FormItem>
                        </Col>
                    </Row>
                    <Row>
                        <Col span={12}>
                            <FormItem {...formItemLayout} label="包装种类" hasFeedback>
                                {getFieldDecorator('kindpackage', {
                                    rules: [{
                                        required: true, message: '请选择包装种类'
                                    }],
                                    initialValue: dataSource.kindpackage ? dataSource.kindpackage.split('|') : []
                                })(
                                    <BizParams disabled={this.props.disabled} sprCode="kindpackage" mode="multiple" onChange={this.handleChangeKindPackage.bind(this)} />
                                    )}
                            </FormItem>
                        </Col>
                        <Col span={12} style={{ display: this.state.packtypeelse ? "inline-block" : "none" }}>
                            <FormItem {...formItemLayout} label="实际种类" hasFeedback>
                                {getFieldDecorator('packtypeelse', {
                                    rules: [{
                                        required: this.state.packtypeelse, message: '请输入实际种类'
                                    }],
                                    initialValue: dataSource.packtypeelse
                                })(
                                    <Input disabled={this.props.disabled} maxLength="20" />
                                    )}
                            </FormItem>
                        </Col>
                    </Row>
                    <Row>
                        <Col span={12}>
                            <FormItem>
                                <Button type="primary" size={'default'} disabled={this.props.disabled} onClick={this.handleOpenAddProduct.bind(this)}>添加产品</Button>
                                {customer.declarationstyle === "2" || customer.csttype === "2" || customer.businessType === "2" ? ""
                                    :
                                    <Button type="primary" style={{ marginLeft: 10, display: this.props.form.getFieldValue("drawertype") === "1" ? "none" : "inline-block" }} size={'default'} disabled={this.props.disabled} onClick={this.handleRefreshAmt.bind(this)}>刷新价格(倒推)</Button>
                                }
                            </FormItem>
                        </Col>
                    </Row>
                </Form>
                <Table rowKey={record => record.id} dataSource={this.state.productList} columns={columns} size={'middle'} style={{ marginTop: 0 }} scroll={{ x: true }} pagination={false} />
                <div style={{ textAlign: 'center', marginTop: 20 }}><span>总数量: </span>{R.isNil(totalnum) ? 0 : totalnum}&nbsp;&nbsp;&nbsp;&nbsp;
                <span>总净重: </span><span>{R.isNil(totalweight) ? 0 : totalweight}&nbsp;kg&nbsp;&nbsp;&nbsp;&nbsp;</span>
                    <span>总毛重: </span><span>{R.isNil(totalgross) ? 0 : totalgross}&nbsp;kg&nbsp;&nbsp;&nbsp;&nbsp;</span>
                    <span>总货值: </span><span>{R.isNil(totleamount) ? 0 : totleamount}&nbsp;{currency}&nbsp;&nbsp;&nbsp;&nbsp;</span>
                    <span>总包装件数: </span><span>{R.isNil(totalpacknum) ? 0 : totalpacknum}</span></div>
                <ChooseProduct wrappedComponentRef={(inst) => this.formRef = inst} handleAddProducts={this.handleAddProducts} dispatch={this.props.dispatch} orderId={dataSource.id} cstId={this.props.cstId} customer={customer}/>
            </div>
        )
    }
})